package com.biodiv.community.controller.login;


import com.biodiv.community.base.ResponseEntity;
import com.biodiv.community.manager.current.ThreadPoolManager;
import com.biodiv.community.request.login.LoginDTO;
import com.biodiv.community.request.login.RegisterDTO;
import com.biodiv.community.response.login.LoginVO;
import com.biodiv.community.service.login.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author tianquan
 */
@Slf4j
@RestController
@RequestMapping("/api")
@AllArgsConstructor
@Tag(name = "登录相关接口")
public class LoginController {

    private final LoginService loginService;
    private final ThreadPoolManager threadPoolManager;

    @PostMapping("/login")
    @Operation(summary = "登录")
    public ResponseEntity<LoginVO> login(@RequestBody LoginDTO loginDTO) {
        return ResponseEntity.success(loginService.login(loginDTO));
    }

    @PostMapping("/register")
    @Operation(summary = "注册")
    public ResponseEntity<Boolean> register(@RequestBody RegisterDTO registerDTO) {
        return ResponseEntity.success(loginService.register(registerDTO));
    }

    @DeleteMapping("/logout")
    @Operation(summary = "退出")
    public ResponseEntity<Void> logout() {
        loginService.logout();
        return ResponseEntity.success();
    }

    @GetMapping("/test")
    public ResponseEntity<Void> test() throws InterruptedException {

        log.info("test");

        threadPoolManager.execute(() -> {
            log.info("test");
        });

        Thread.sleep(10000);

        return ResponseEntity.success();
    }


}
